package com.inossem.allotin.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 时间工具类
 *
 * @author 詹建宇
 * @time on 2018/11/20 17:22
 * @email jianyu.zhan@inossem.com
 */
public class TimeUtils {

    /**
     * 获取当前年月日
     *
     * @param division 分隔符
     * @return 时间
     */
    public static String getNowTime(String division) {
        if (null == division) division = "";

        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);

        return year + division + month + division + day;
    }

    public static String getCurrentDetailTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日-HH:mm:ss", Locale.CHINESE);
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

    /**
     * String转Date
     */
    public static Date transitionStringToData(String s) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
        try {
            return sdf.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * String转Date
     */
    public static Date transitionStringToData1(String s) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);
        try {
            return sdf.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取时间戳
     */
    public static int getTimeSeal() {
        return (int) (System.currentTimeMillis() / 1000);
    }

    /**
     * date转string
     *
     * @param date
     * @return
     */
    public static String transitionDateToString(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
        String str = sdf.format(date);
        return str;
    }

}
